<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">
			<title>海科集团任务监督管理系统-首页</title>
			<style>
				.datagrid-row,
				.datagrid-row-over {
					/* 	background: green; */

				}

				#center {
					/* 	width: 1200px; */
					margin: 0 auto;
				}

				#left {
					float: left;
				}

				#right {
					float: left;
					margin-left: 30px;
					margin-right: 0;
					/* 	width: 400px; */
				}

				.table tr {
					height: 20px;
				}

				.left {
					font-weight: bold;
				}
			</style>
		</head>

		<body>
			<%@ include file="TaskHeader.jsp" %>
				<script>
					$(document).ready(function () {
						$("#first a .out").stop().animate({
							'top': '48px'
						}, 300); // move down - hide
						$("#first a .over").stop().animate({
							'top': '0px'
						}, 300); // move down - show
					});
				</script>
				<div id="center">
					<div style="margin: 20px 0;">
						<input type="hidden" id="currentyear" value="${currentyear}" /> <input type="hidden"
							id="currentweek" value="${currentweek}" />
					</div>
					<table>
						<tr>
							<td>
								<div id="left">
									<table class="easyui-datagrid" id="ttall">
									</table>
								</div>
							</td>
							<td>
								<div id="right">
									<table class="easyui-datagrid" id="ttmy">
									</table>
								</div>
							</td>
						</tr>
					</table>
				</div>
				<div id="dlg" class="easyui-dialog" style="width: 700px; height: 500px;"
					data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
					<form id="fm" method="post" novalidate style="margin: 0; padding: 20px 50px"
						enctype="multipart/form-data">
						<table class="table">
							<tr>
								<td class="left"><span>会议名称:</span></td>
								<td><span id="meetName"></span></td>
							</tr>
							<tr style="height: 18px;"></tr>
							<tr>
								<td class="left"><span>督办事项:</span></td>
								<td><span id="surpviseName"></span></td>
							</tr>
							<tr style="height: 28px;"></tr>
							<tr>
								<td class="left"><span>本周工作:</span><input id="infid" type="hidden" /></td>
								<td><textarea name="taskinfo" id="taskinfo" cols="60" rows="7"
										style="OVERFLOW: hidden"></textarea></td>
							</tr>
							<tr style="height: 28px;"></tr>
							<tr>
								<td class="left"><span>整体进度:</span></td>
								<td><input class="easyui-slider" style="width: 300px" id="slideProgress" data-options="showTip:true,
                rule: [0,'|',20,'|',40,'|',60,'|',80,'|',100]" value="0"></td>
							</tr>
							<tr style="height: 38px;"></tr>
							<tr>
								<td style="width: 120px;" class="left"><span>计划完成时间:</span></td>
								<td><input class="easyui-datebox" id="datePlan" required="required"
										style="width: 180px;"> <br /></td>
							</tr>
							<!-- 				<tr> -->
							<!-- 					<td>附件：</td> -->
							<!-- 					<td><input type="file" name="file" id="file"><input -->
							<!-- 						type="button" onclick="upload()" value="上传" />
<div class="formtitle upLoad">附件上传</div>
  <div class="chooseFile" style="height: auto;">
      <input type="button" id="uploadbtn" value="选择文件..." /><input type="button" id="uploadfile" style="display: none;" value="上传文件" />
      <input type="file" id="uploadpicker" accept="" style="display: none;" multiple />
      <div>
          <ul id="checkfileList"></ul>
      </div>
 </div>
</td> -->
							<!-- 				</tr> -->

						</table>
					</form>
				</div>
				<div id="dlg-buttons">
					<a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-save" onclick="save()"
						style="width: 90px">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton c6"
						iconCls="icon-ok" onclick="commit()" style="width: 90px">提交</a> <a href="javascript:void(0)"
						class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')"
						style="width: 90px">关闭</a>
				</div>
				<script>
					var selectedFileList = [];//已选文件列表
					var paramTaskId = "";//请求参数
					var succsessCount = 0;//上传成功文件个数
					var errorCount = 0;//上传失败文件个数
					$(function () {
						$("#uploadbtn").bind("click", function (e) {
							$("#uploadpicker").click();
						});
						$("#uploadpicker")
							.bind(
								"change",
								function () {//绑定文件选择事件
									var files = $("#uploadpicker").prop("files");
									$
										.each(
											files,
											function (index, item) {
												var choiseFile = $("#checkfileList>li");
												if (choiseFile.length > 0) {//文件去重
													var count = 0;
													$
														.each(
															choiseFile,
															function (
																index1,
																item1) {
																if (item.name == item1.innerText) {
																	count++;
																}
															});
													if (count == 0) {
														if (checkFileLength(item.size)) {
															if (item.name.includes('&') || item.name.includes(' ')) {
																alert('文件名不能包含&、空格等特殊字符！');
																return;
															}
															$(
																"#checkfileList")
																.append(
																	"<li class=\"fileinfo\">"
																	+ item.name
																	+ "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this)\">删除</a>"
																	+ "</li>");
															selectedFileList
																.push(item);
															AddMoushover();
														}
													}
												} else {
													if (checkFileLength(item.size)) {
														if (item.name.includes('&') || item.name.includes(' ')) {
															alert('文件名不能包含&、空格等特殊字符！');
															return;
														}
														$("#checkfileList")
															.append(
																"<li class=\"fileinfo\">"
																+ item.name
																+ "<a style=\"display: none; color: red; margin-left: 10px;\" href=\"javascript:void(0)\" onclick=\"RemoveFile(this)\">删除</a>"
																+ "</li>");
														selectedFileList
															.push(item);
														AddMoushover();
													}
												}
											});
								});
						AddMoushover();
					});
					//判断文件是否超过限制大小
					function checkFileLength(fileLen) {
						if (fileLen > 4194304) {
							$.messager.alert("提示", "上传文件大小不能超过4M", "error");
							return false;
						}
						return true;
					}
					//上传文件
					function uploadFile() {
						if (selectedFileList.length > 0) {
							$.messager.progress({
								title: "提示",
								msg: "文件上传中..."
							});
							$
								.each(
									selectedFileList,
									function (index, item) {
										debugger;
										var dataform = new FormData();
										dataform.append("file", item);
										var xmlhttp = null;
										if (window.XMLHttpRequest) {// code for all new browsers
											xmlhttp = new XMLHttpRequest();
										} else if (window.ActiveXObject) {// code for IE5 and IE6
											xmlhttp = new ActiveXObject(
												"Microsoft.XMLHTTP");
										}
										if (xmlhttp != null) {
											xmlhttp.open("POST",
												"/Project/ProjectTask/SaveFiles?TaskId="
												+ paramTaskId, true);
											xmlhttp.send(dataform);
											xmlhttp.onreadystatechange = callbackMethods;
										} else {
											alert("你的浏览器版本不兼容，请使用更高版本的浏览器");
										}
										function callbackMethods() {
											debugger;
											if (xmlhttp.readyState == 4) {
												if (xmlhttp.status == 200) {
													succsessCount++;
													if ((succsessCount + errorCount) == selectedFileList.length) {
														if (errorCount > 0) {
															$.messager
																.alert(
																	"提示",
																	"上传文件完成,"
																	+ errorCount
																	+ "个文件由于过大上传失败。",
																	"error");
														}
														submitSuccess();
													}
												} else {
													if (xmlhttp.status == 500) {
														errorCount++;
														if ((succsessCount + errorCount) == selectedFileList.length) {
															if (errorCount > 0) {
																$.messager
																	.alert(
																		"提示",
																		"上传文件完成,"
																		+ errorCount
																		+ "个文件由于过大上传失败。",
																		"error");
															}
															submitSuccess();
														}
													}
												}
											}
										}
									});

						} else {
							submitSuccess();
						}
					}
					//移除已选择的文件
					function RemoveFile(obj) {
						$.messager.confirm("提示", "确认删除当前文件?", function (e) {
							if (e) {
								var index = $("#checkfileList>li").index($(obj).parent());
								selectedFileList.splice(index, 1);
								$(obj).parent().remove();
							}
						});
					}
					//添加鼠标经过事件，鼠标划过时显示“删除”
					function AddMoushover() {
						$(".fileinfo").hover(function () {
							$(this).find("a").last().css("display", "");
						}, function () {
							$(this).find("a").last().css("display", "none");
						});
					}
				</script>
				<script>
					function editForm(rowindex) {
						$('#dlg').dialog('open').dialog('center').dialog('setTitle',
							'任务填报（友情提示：本周只可提交一次）');
						$('#fm').form('clear');
						var rows = $('#ttmy').datagrid("getRows");
						var row = rows[rowindex];
						$('#infid').val(row['INF_ID']);
						$('#taskinfo').val(row['PROR_CONTENT']);
						$('#surpviseName').html(row['PRO_CONTENT']);
						$('#meetName').html(row['INF_METTINGNAME']);
						if (row['PROR_PROGRESS'] != null) {
							$('#slideProgress').slider('setValue', row['PROR_PROGRESS']);//保存后从result表中提取本周值
						} else {
							$('#slideProgress').slider('setValue', row['PRO_COEE']);//第一次从project表中提取，因为本周还没录入进度
						}
						setPlandate(row['PRO_PLANFINISHDATE'], row["PRO_ID"]);//当第一次提交后计划日期不可再变 
						if (row['PROR_COMMITTIME'] != null) {
							$('#dlg-buttons').hide();
						} else {
							$('#dlg-buttons').show();
						}
					}
					function setPlandate(plandate, proId) {
						$.ajax({
							type: "post",
							url: "task/selectResultCommitNum",
							data: {
								inf_id: $('#infid').val(),
								proId: proId
							},
							success: function (data) {
								if (data > 0) {
									$('#datePlan').datebox('readonly');
								} else {
									$('#datePlan').datebox('readonly', false);
								}
								$('#datePlan').datebox('setValue', plandate);
								$('#datePlan').datebox('setText', plandate);
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								$.messager.alert('消息', errorThrown);
							}
						});
					}
					function commit() {
						if (!$('#fm').form('validate')) {
							return;
						}
						if ($('#datePlan').datebox('getText') == null) {
							$.messager.alert('消息', '请选择计划完成日期');
						}
						var row = $('#ttmy').datagrid('getSelected');
						$.messager.confirm('请确认', '本周只能提交一次，提交后无法修改，确认提交?', function (r) {
							if (r) {
								$.ajax({
									type: "post",
									url: "task/commitProjectresult",
									data: {
										inf_id: $('#infid').val(),
										content: $('#taskinfo').val(),
										progress: $('#slideProgress').slider('getValue'),
										planDate: $('#datePlan').datebox('getText'),
										proId: row["PRO_ID"]
									},
									success: function (data) {
										$.messager.alert('消息', data);
										if (data == '提交成功!') {
											$('#dlg').dialog('close');
											bindgridmy();//因为关闭窗口，所以刷新
											bindgridall();
										}
									},
									error: function (XMLHttpRequest, textStatus,
										errorThrown) {
										$.messager.alert('消息', errorThrown);
									}
								});
							}
						});
					}
					function upload() {
						var formdata = new FormData($("#fm")[0]);
						console.log(formdata);
						$.ajax({
							type: "post",
							url: "task/upload",
							data: formdata,
							//                 dataType: 'JSON',
							contentType: false,
							processData: false,
							success: function (data) {
								$.messager.alert('消息', data);
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								$.messager.alert('消息', errorThrown);
							}
						});
					}

					function save() {
						if (!$('#fm').form('validate')) {
							return;
						}
						if ($('#datePlan').datebox('getText') == null) {
							$.messager.alert('消息', '请选择计划完成日期');
						}
						var row = $('#ttmy').datagrid('getSelected');

						$.ajax({
							type: "post",
							url: "task/saveProjectresult",
							data: {
								inf_id: $('#infid').val(),
								content: $('#taskinfo').val(),
								progress: $('#slideProgress').slider('getValue'),
								planDate: $('#datePlan').datebox('getText'),
								proId: row["PRO_ID"]
							},
							success: function (data) {
								$.messager.alert('消息', data);
								if (data == '保存成功!') {
								}
								$('#dlg').dialog('close');
								bindgridmy();//因为关闭窗口，所以刷新
								bindgridall();
							},
							error: function (XMLHttpRequest, textStatus, errorThrown) {
								$.messager.alert('消息', errorThrown);
							}
						});
					}
				</script>
				<script>
					//获取当前时间，格式YYYY-MM-DD
					function getNowFormatDate() {
						var date = new Date();
						var seperator1 = "-";
						var year = date.getFullYear();
						var month = date.getMonth() + 1;
						var strDate = date.getDate();
						if (month >= 1 && month <= 9) {
							month = "0" + month;
						}
						if (strDate >= 0 && strDate <= 9) {
							strDate = "0" + strDate;
						}
						var currentdate = year + seperator1 + month + seperator1 + strDate;
						return currentdate;
					}
				</script>

				<script>
					$(function () {
						bindgridall();
						bindgridmy();
						$('#center').width($(window).width() - 50);

					})

					function bindgridall() {
						$('#ttall')
							.datagrid(
								{
									title: '本周督办',
									nowrap: false,
									rownumbers: true,
									singleSelect: true,
									collapsible: true,
									width: $(window).width() - 600,
									height: 500,
									rownumbers: true,
									url: 'default/selectWeektask',
									columns: [[
										{
											field: 'INF_METTINGNAME',
											title: '会议名称',
											width: '20%',
											formatter: function (val, rec) {
												var complete = val;
												if (rec.PROR_COMMITTIME != null) {
													complete = val
														+ '<img src="resourse/img/BDNew_wev8.png"/>'
												}
												var str = '<a target="_blank" href="SurpviseManage/surpviseView?inf_id='
													+ rec.INF_ID
													+ '&year='
													+ $('#currentyear')
														.val()
													+ '&week='
													+ $('#currentweek')
														.val()
													+ '">'
													+ complete + '</a>';
												return str;
											}
										},
										{
											field: 'PRO_CONTENT',
											title: '督办事项',
											width: '30%',
											formatter: function (val, rec) {
												return val;
											}
										},
										{
											field: 'PRO_COEE',
											title: '整体进度',
											// 											width : 70,
											formatter: function (val, rec) {
												if (val == null) {
													val = 0;
												}
												var tempval = val;
												var htmlstr = '';
												var flag = false;
												//判断是否超期
												if (rec.PRO_VALIDATETIME == null
													&& rec.PRO_PLANFINISHDATE < getNowFormatDate()) {
													flag = true;//当没有完成时间时，与当前时间比较
												}
												if (rec.PRO_VALIDATETIME != null
													&& rec.PRO_PLANFINISHDATE < rec.PRO_VALIDATETIME.substr(0, 10)) {
													flag = true;//当有完成时间时，与完成时间比较
												}
												if (rec.PRO_PLANFINISHDATE == null
													|| rec.PRO_PLANFINISHDATE == "") {
													flag = false;
												}
												if (flag) {
													htmlstr = '<div class="easyui-progressbar progressbar" style="width: 60px;font-weight:bold; " value="'
														+ tempval
														+ '" text="'
														+ tempval
														+ '%">'
														+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;font-weight:bold;color:red; ">'
														+ tempval
														+ '%</div>'
														+ '<div class="progressbar-value" style="width: '
														+ tempval
														+ '%; height: 20px; line-height: 20px; color:red;font-weight:bold;">'
														+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;font-weight:bold;color:red;">'
														+ tempval
														+ '%</div>'
														+ '</div>'
														+ '</div>';
												} else {
													htmlstr = '<div class="easyui-progressbar progressbar" style="width: 60px; " value="'
														+ tempval
														+ '" text="'
														+ tempval
														+ '%">'
														+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;">'
														+ tempval
														+ '%</div>'
														+ '<div class="progressbar-value" style="width: '
														+ tempval
														+ '%; height: 20px; line-height: 20px;">'
														+ '<div class="progressbar-text" style="width: 60px; height: 20px; line-height: 20px;">'
														+ tempval
														+ '%</div>'
														+ '</div>'
														+ '</div>';
												}
												return htmlstr;
											}
										},
										{
											field: 'PROR_CONTENT',
											title: '本周工作',
											width: '20%',
											formatter: function (val, rec) {
												return val;
											}
										},
										{
											field: 'PRO_PLANFINISHDATE',
											title: '计划完成时间',
											width: 90,
											formatter: function (val, rec) {
												if (val != null) {
													return (val + '').substr(0,
														10);
												} else {
													return val;
												}
											}
										}, {
											field: 'PRO_EXECUTEUSERNAME',
											title: '执行人',
											// 											width : 40,
											formatter: function (val, rec) {
												return val;
											}
										}]],
									rowStyler: function (index, row) {
										if (row.PROR_COMMITTIME == null) {
											// 										return 'background-color:#f6ffc0;color:blue;font-weight:bold;';
										} else {
											// 										return 'background-color:#17f709;color:blue;font-weight:bold;';
										}
									},
									onLoadSuccess: onLoadSuccess
								});
					}

					function onLoadSuccess(data) {

					}
					function bindgridmy() {
						$('#ttmy')
							.datagrid(
								{
									title: '本周待办',
									singleSelect: true,
									nowrap: false,
									width: 500,
									height: 500,
									url: 'default/selectMytask',
									rownumbers: true,
									columns: [[
										{
											field: 'INF_METTINGNAME',
											title: '会议名称',
											width: 200,
											formatter: function (val, rec) {
												return val;
											}
										},
										{
											field: 'PRO_CONTENT',
											title: '督办事项',
											width: 200,
											formatter: function (val, rec) {
												return val;
											}
										},
										{
											field: 'edit',
											title: '',
											// 											width : 40,
											formatter: function (val, rec,
												index) {
												if (rec.PROR_COMMITTIME == null) {
													var str = '<a href="javascript:void(0)" onclick="editForm('
														+ index
														+ ')">编辑</a>';
													return str;
												} else {
													var str = '<a href="javascript:void(0)" onclick="editForm('
														+ index
														+ ')">查看</a>';
													return str;
												}
											}
										}]],
									rowStyler: function (index, row) {
										if (row.PROR_COMMITTIME == null) {
											// 										return 'background-color:#f6ffc0;color:blue;font-weight:bold;';
										} else {
											// 										return 'background-color:#17f709;color:blue;font-weight:bold;';
										}
									}
								});
					}
				</script>
		</body>

		</html>